//package com.springboot.geotoos;
//
//import java.io.File;
//import java.io.IOException;
//import java.net.MalformedURLException;
//import java.nio.charset.Charset;
//import java.sql.Connection;
//import java.sql.DriverManager;
//import java.sql.PreparedStatement;
//import java.sql.SQLException;
//import java.util.*;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
//import org.apache.commons.lang3.StringUtils;
//import org.geotools.data.*;
//import org.geotools.data.mysql.MySQLDataStoreFactory;
//import org.geotools.data.shapefile.ShapefileDataStore;
//import org.geotools.data.shapefile.dbf.DbaseFileHeader;
//import org.geotools.data.shapefile.dbf.DbaseFileReader;
//import org.geotools.data.shapefile.files.ShpFiles;
//import org.geotools.data.simple.SimpleFeatureCollection;
//import org.geotools.data.simple.SimpleFeatureIterator;
//import org.geotools.data.simple.SimpleFeatureSource;
//import org.geotools.data.store.ContentEntry;
//import org.geotools.feature.FeatureCollection;
//import org.geotools.feature.FeatureIterator;
//import org.geotools.feature.NameImpl;
//import org.geotools.feature.simple.SimpleFeatureBuilder;
//import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
//import org.geotools.geometry.jts.JTSFactoryFinder;
//import org.geotools.jdbc.JDBCDataStore;
//
//import org.locationtech.jts.geom.GeometryFactory;
//import org.locationtech.jts.geom.MultiPolygon;
//import org.locationtech.jts.geom.Point;
//import org.locationtech.jts.geom.Polygon;
//import org.opengis.feature.Property;
//import org.opengis.feature.simple.SimpleFeature;
//import org.opengis.feature.simple.SimpleFeatureType;
//import org.opengis.feature.type.AttributeDescriptor;
//
//import javax.management.j2ee.statistics.JDBCStats;
//
///**
// * @Description
// * @Author 顾志杰
// * @Date 2021/11/10 14:49
// */
//public class ToMysql {
//
//
//
//    public static void main(String[] args) throws SQLException {
//
//
//        String[] type = new String[]{"喷泉.shx", "售货亭.shx", "公交站亭.shx", "特殊井盖.shx", "雨水箅子.shx", "交通信号设施.shx",
//                "地灯.shx", "地名牌.shx", "公共厕所.shx", "电力井盖.shx", "交通信号灯.shx", "变压器（箱）.shx",
//                "旗杆.shx", "垃圾箱.shx", "公安井盖.shx", "电力立杆.shx", "交通标志牌.shx", "垃圾间（楼）.shx",
//                "水井.shx", "安全岛.shx", "古树名木.shx", "电力设施.shx", "公厕指示牌.shx", "户外健身设施.shx",
//                "路灯.shx", "宣传栏.shx", "园林井盖.shx", "电缆井盖.shx", "出租车站牌.shx", "水域附属设施.shx",
//                "邮筒.shx", "景观灯.shx", "户外广告.shx", "电视井盖.shx", "化粪池井盖.shx", "绿地附属设施.shx",
//                "雕塑.shx", "跨河桥.shx", "文物古迹.shx", "街头坐椅.shx", "水域标示牌.shx", "输油（气）井盖.shx",
//                "休息亭.shx", "路名牌.shx", "污水井盖.shx", "跨河管道.shx", "监控电子眼.shx", "道路信息显示屏.shx",
//                "供水器.shx", "防汛墙.shx", "治安岗亭.shx", "路灯井盖.shx", "自动售货机.shx", "非机动车停放点.shx",
//                "信息亭.shx", "上水井盖.shx", "消防设施.shx", "通信井盖.shx", "通信交接箱.shx", "燃气调压站（箱）.shx",
//                "停车场.shx", "不明井盖.shx", "燃气井盖.shx", "通信立杆.shx", "限高架标志.shx", "车辆加油（气、电）站.shx",
//                "充电桩.shx", "交通岗亭.shx", "牌匾标识.shx", "雨水井盖.shx", "高压线铁塔.shx",};
//
//
//
//        Connection root = DriverManager.getConnection("jdbc:mysql://localhost:3306/gis", "root", "123456");
//
//
////        for (String s : type) {
//            ShapefileDataStore shpDataStore = null;
//            try{
//                shpDataStore = new ShapefileDataStore(new File("/Users/guzhijie/Downloads/户外广告/户外广告.shx").toURI().toURL());
//                shpDataStore.setCharset(Charset.forName("GBK"));
//                String typeName = shpDataStore.getTypeNames()[0];
////                System.out.println(typeName);
//                FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
//                featureSource = shpDataStore.getFeatureSource(typeName);
//                FeatureCollection<SimpleFeatureType, SimpleFeature> result = featureSource.getFeatures();
//                FeatureIterator<SimpleFeature> itertor = result.features();
//                List<Gis> list = new ArrayList<>();
//                GeometryFactory geometryFactory = new GeometryFactory();
//                while(itertor.hasNext()){
//                    SimpleFeature feature = itertor.next();
//                    Collection<Property> p = feature.getProperties();
//                    Gis gis = new Gis();
//                    gis.setName(feature.getID());
//                    System.out.println(feature.getID()+"-------------------------------");
//                    for (Property pro : p) {
////                        if(pro.getValue() instanceof MultiPolygon){
////                            MultiPolygon value = (MultiPolygon)pro.getValue();
////                            gis.setPoint(geometryFactory.createPolygon(value.getCoordinates()));
////                        }else if(pro.getName().toString().equals("commcode")){
////                            gis.setPCode(pro.getValue().toString());
////                        }else if(pro.getName().toString().equals("gridcode")){
////                            gis.setCode(pro.getValue().toString());
////                        }else if(pro.getName().toString().equals("commname")){
////                            gis.setPName(pro.getValue().toString());
////                        }else if(pro.getName().toString().equals("strecode")){
////                            gis.setPpCode(pro.getValue().toString());
////                        }else if(pro.getName().toString().equals("stretname")){
////                            gis.setPPName(pro.getValue().toString());
////                        }
//
//                        System.out.println(pro.getName()+":"+pro.getValue());
//                    }
//                    list.add(gis);
//
//                }
//                itertor.close();
//                Stream<Gis> gisStream = list.parallelStream().filter(l -> StringUtils.isNotBlank(l.getName()));
//
////                Map<String, List<Gis>> collect = gisStream.collect(Collectors.groupingBy(Gis::getPPName));
////                collect.keySet().forEach(s-> {
////                    String ppId = UUID.randomUUID().toString();
////                    String ppSql = "INSERT INTO `grid` (`id`, `area`, `grid_code`, `grid_name`, `geom`, `initial_date`, `level`, `remark`, `termination_date`, `dept_id`, `parent_id`, `publish_id`, `record_id`, `kv_id`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`) VALUES ('"+ppId+"', NULL, '"+collect.get(s).get(0).getPpCode()+"', '"+s+"', NULL, NULL, 2, '霞浦县', NULL, NULL, '0d449e35-72db-4c4b-ad1c-3501396f501c', NULL, NULL, NULL, '0', '2022-04-23 16:03:31', '2022-04-23 16:03:31', '1', '1');";
////                    sql(ppSql,root);
////                    Map<String, List<Gis>> pList = collect.get(s).parallelStream().collect(Collectors.groupingBy(Gis::getPName));
////                    pList.keySet().forEach(p->{
////                        String pId = UUID.randomUUID().toString();
////                        String pSql = "INSERT INTO `grid` (`id`, `area`, `grid_code`, `grid_name`, `geom`, `initial_date`, `level`, `remark`, `termination_date`, `dept_id`, `parent_id`, `publish_id`, `record_id`, `kv_id`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`) VALUES ('"+pId+"', NULL, '"+ pList.get(p).get(0).getPCode()+"', '"+p+"', NULL, NULL, 3, '"+s+"', NULL, NULL, '"+ppId+"', NULL, NULL, NULL, '0', '2022-04-23 16:03:31', '2022-04-23 16:03:31', '1', '1');";
////                        sql(pSql,root);
////                        pList.get(p).forEach(g->{
////                            String sql = "INSERT INTO `grid` (`id`, `area`, `grid_code`, `grid_name`, `geom`, `initial_date`, `level`, `remark`, `termination_date`, `dept_id`, `parent_id`, `publish_id`, `record_id`, `kv_id`, `deleted`, `create_time`, `update_time`, `create_by`, `update_by`) VALUES ('"+UUID.randomUUID().toString()+"', NULL, '"+g.getCode()+"', '"+g.getName()+"', ST_GeomFromText('"+g.getPoint()+"'), NULL, 4, '"+p+"', NULL, NULL, '"+pId+"', NULL, NULL, NULL, '0', '2022-04-23 16:03:31', '2022-04-23 16:03:31', '1', '1');";
////                            sql(sql,root);
////                        });
////                    });
////
////                });
//
//
////                gisStream.forEach(g->{
////                    String sql = "INSERT INTO unit (`id`, `obg_name`, `obg_id`, `point`, `pic_address`) VALUES ('"+UUID.randomUUID()+"', '"+g.getName()+"','"+g.getCode()+"', ST_GeomFromText('"+g.getPoint()+"'), '"+g.getUrl()+"');";
//
////                });
//            } catch (MalformedURLException e) {
//                e.printStackTrace();
//            } catch(IOException e) { e.printStackTrace(); }
////        }
//
//
//
//        root.close();
//    }
//
//    private static void sql(String sql, Connection root){
//        try {
//            PreparedStatement ps = root.prepareStatement(sql);
//            ps.execute();
//            ps.close();
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//    }
//
//
////    public static void main(String[] args) {
////        DbaseFileReader reader = null;
////        try {
////            reader = new DbaseFileReader(new ShpFiles("/Users/guzhijie/Downloads/伊春地图普查库/地理编码/yc.shp"), false,
////                    Charset.forName("GBK"));
////            DbaseFileHeader header = reader.getHeader();
////            int numFields = header.getNumFields();
////
////            while (reader.hasNext()) {
////                try {
////                    Object[] entry = reader.readEntry();
////                    for (int i = 0; i < numFields; i++) {
////                        String title = header.getFieldName(i);
////                        Object value = entry[i];
////                        System.out.println(title + "=" + value);
////                    }
////                } catch (Exception e) {
////                    e.printStackTrace();
////                }
////            }
////        } catch (Exception e) {
////            e.printStackTrace();
////        } finally {
////            if (reader != null) {
////
////                try {
////                    reader.close();
////                } catch (Exception e) {
////                }
////            }
////        }
////    }
//}
//
//
